package mblog.core.persist.dao.impl;

import mblog.core.persist.dao.MaterialDao;
import mblog.core.persist.dao.WzclCgJsjdDao;
import mblog.core.persist.entity.PMaterialPO;
import mblog.core.persist.entity.WzclCgJsjdPO;
import mtons.modules.annotation.Repository;
import mtons.modules.persist.impl.BaseRepositoryImpl;
import mtons.modules.pojos.Paging;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import java.util.List;

/**
 * @author Beldon
 */
@Repository(entity = WzclCgJsjdPO.class)
public class WzclCgJsjdDaoImpl extends BaseRepositoryImpl<WzclCgJsjdPO> implements WzclCgJsjdDao {
	private static final long serialVersionUID = 754755214307906383L;

    @Override
    public void save(WzclCgJsjdPO entity) {

    }

    @Override
    public void delete(long id) {

    }

    @Override
    public WzclCgJsjdPO findById(long id) {
        return null;
    }

    @Override
	@SuppressWarnings("unchecked")
    public List<WzclCgJsjdPO> findAll(){
        Query query = createQuery("from WzclCgJsjdPO am order by am.updateTime desc");
        return query.list();
    }

    @Override
    public List<WzclCgJsjdPO> paging(Paging paging, String key) {
        PagingQuery<WzclCgJsjdPO> q = pagingQuery(paging);
        if (StringUtils.isNotBlank(key)) {
            q.add(Restrictions.or(
                    Restrictions.like("dwgc", key, MatchMode.ANYWHERE),
                    Restrictions.like("jfdw", key, MatchMode.ANYWHERE)
            ));
        }
        q.add(Restrictions.eq("isDel",0));
        q.desc("id");
        return q.list();
    }

}
